package com.example.springboot.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.hystrix.annocation.DoHystrix;

@RestController
public class HystrixController {
	private Logger logger = LoggerFactory.getLogger(HystrixController.class);
	
	/**
	 * 测试：http://localhost:8081/api/queryUserInfo?userId=aaa
	 */
	@DoHystrix(timeoutValue = 350, returnJson = "{\"code\":\"1111\",\"info\":\"调用方法超过350毫秒，熔断返回！\"}")
	@GetMapping("/api/hystrix/queryUserInfo")
	public UserInfo queryUserInfo(@RequestParam String userId) throws InterruptedException {
		logger.info("查询用户信息，userId：{}", userId);
		Thread.sleep(100);
//		Thread.sleep(1000);
		return new UserInfo("虫虫:" + userId, 19, "天津市东丽区万科赏溪苑14-0000");
	}
	
}
